import $axios from "@/common/http.js";//请求实例
import { Message } from "element-ui";
import router from "@/router"

/**
 * 
 * @returns 获取商品列表  分页
 */

export const getGoodslist = async (data) => {
    let rst = await $axios({
        url: '/goodslist',
        params: {
            ...data
        }

    })
    return rst
}
/**
 * 
 * @returns  分页总页数
 */
export const contotal = async () => {
    let { list } = await $axios.get('/goodscount')
    return list
}



export const getSpecslist = async () => {
    return await $axios.get('/specslist')
}


/**
 * 添加商品
 * @param {*} data 
 */
export const addSpecs = async (data) => {
    let rst = await $axios.post('/goodsadd', data)
    if (rst.code == 200) {
        Message({
            type: "success",
            message: rst.msg,
            duration: 500,
            onClose() {//关闭之后，回到页面
                router.go(-1);
            }
        })
    }
}


/**
 * 根据id查一条
 * @param {*} id 
 * @returns 
 */
export const Specsinof = async (id) => {
    return await $axios.get('/goodsinfo', { params: { id } })
}


/**
 *  改数据
 * @param {*} data 
 */
export const editSpecs = async (data) => {
    let rst = await $axios.post('/goodsedit', data)
    if (rst.code == 200) {
        Message({
            type: "success",
            message: rst.msg,
            duration: 500,
            onClose() {//关闭之后，回到页面
                router.go(-1);
            }
        })
    }
}


/**
 * 根据id删除一条
 * @param {*} id 
 * @returns 
 */

export const delSpecs = async (id) => {
    let rst = await $axios.post('/goodsdelete', { id })
    if (rst.code == 200) {
        Message({
            type: "success",
            message: rst.msg,
            duration: 500,

        })
        return true
    } else {
        return false
    }
}

